A program call stack provides a representation of entries in a memory device in which data may be stored. Each function in a program is associated with a frame in a call stack, where the frame designates sequential entries in the call stack to store state information for the function, such as local variables, arguments, caller/callee saved registers, register spills, spilled function arguments, return values, etc. Each thread of execution has its own call stack, where a thread is an independent flow of control execution. The frame in a call stack maps to call stack frame entries in one memory device. When a function is invoked, its frame is allocated at the top of the call stack. When the function returns, the frame is de-allocated. In this way, the memory locations represented by the stack are allocated per process and generally grow down in memory. When a function is called, the state information of the calling function is preserved so that when the called function returns, the calling function can resume execution. The compiler generates code to increase the size of the stack upon entry to a function, and decreases the size of the stack upon exit from a function, as well as saving and restoring the values of registers.
Function frames are typically allocated as a single call stack frame entry (as opposed to a fixed memory location for each function frame). Furthermore, the call stack along with calling convention provides the function scope for the compiler to operate.
Certain processing devices, such as network processors, include multiple packet processors, also known as packet engines, that may reuse and execute the same code. Network processors also utilize multiple memory devices, such as a local memory, scratch memory, Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), etc. In such devices using a multi-level memory hierarchy, each memory level, i.e., device, is accessed with its own set of instructions, registers, and address space. In such network processor devices, a call stack is not used, and state information for the functions called by the different packet processors are allocated to static locations in the different memory devices.